//目录
<template>
    <div ref="catalog" class="catalog">
        <!-- <a-page-header sub-title="目录"></a-page-header> -->
        <div class="top" @click="$emit('closeCatalog')">
            <a-icon type="arrow-left" style="font-size:18px;line-height:33px" />返回
        </div>
        <ul>
            <li
                v-for="(item,index) in catalog"
                :key="item.chapterUrl"
                :class="{current:index===currentChapter}"
                @click="$emit('change-chapter',index)"
            >{{index}}、{{item.chapterName}}</li>
        </ul>
    </div>
</template>

<script>
import {Icon} from 'ant-design-vue'

export default {
    name: "ReaderCatalog",
    components:{
        'a-icon':Icon
    },
    data: () => {
        return {};
    },
    props: ["catalog", "currentChapter", "isScrollCatalog"],
    watch: {
        currentChapter: function (val) {
            this.$refs.catalog.scrollTop = 36 * val;
        },
    },
    methods: {},
};
</script>

<style scoped>
.current {
    background: lightgray;
}
.catalog {
    background: white;
    font-size: 12px;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    overflow: auto;
}
ul {
    /* position: absolute */
    position: relative;
    height: auto;
    display: block;
}
li {
    font-size: 16px;
    line-height: 35px;
    border-bottom: 1px dashed black;
    height: 35px;
    overflow: hidden;
}
.top {
    width: 100%;
    height: 30px;
    position: fixed;
    z-index: 1;
    background: white;
}
@media screen and (max-width: 420px) {
    .top {
        top: 0px;
    }
    .catalog {
        padding-top: 35px;
    }
}
@media screen and (min-width: 420px) {
    .top {
        top: 33px;
    }
    .catalog {
        padding-top: 70px;
    }
}
</style>

